import greenfoot.*;  // (World, Actor, GreenfootImage, and Greenfoot)
import java.util.List;

/**
 * Bomba se activa con botón X
 * 
 * @author Alejandro Caldera
 */
public class Bomb extends Actor
{
    private static final int NUM_FRAGMENTS = 40;
    
    /**
     * Act - do whatever the Rock wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        //Checa si s epresiona X para explotar bombas
        if (Greenfoot.isKeyDown("x")) {
            explode();
         
         
          
          
          
        }
    }
    
    /**
       Función que hace explotar la bomba.
     */ 
    
    public void explode()
    {
        getWorld().removeObjects(getObjectsInRange(80, Plaga.class));
        placeDebris (getX(), getY(), NUM_FRAGMENTS);
        getWorld().removeObject(this);
         
    }
    
    /**
       Función simula la fragmetación de la bomba.
     */ 
    private void placeDebris(int x, int y, int numFragments)
    {
        for (int i=0; i < numFragments; i++) {
            getWorld().addObject ( new Debris(), x, y );
        }
    }
    
    
}
